import numpy as np
import matplotlib.pyplot as plt

# 假设这是您输入的三个曲线数据（y值范围0-2）
# 示例数据：三条曲线的y值数组（x轴默认按索引生成）
curve1_y = np.array([0.0,0, 0.4070921922372427, 0.3968542811959062, 0.39349595255779485, 0.41064261109563827, 0.39026286727360954, 0.3798191827944994, 0.33158949217705747, 0.3208032733165951, 0.31073065790566406, 0.3208889203254683, 0.30711714079706537, 0.3006855873524475, 0.2988050577391581, 0.2898938324951599, 0.2891446838350022, 0.2978469963552205, 0.298755439496222, 0.3006585455974534, 0.29850285083361966, 0.2954809137540873, 0.29216535773011526, 0.29862035138659615, 0.3004293506613445, 0.32278948427807047, 0.32100311133507453, 0.33084271549266975, 0.3304723347367284, 0.3296186074079544])
curve2_y = np.array([0.0,0, 0.529899838292087, 0.5522468185767884, 0.5074671818482673, 0.5169480084259049, 0.47303315331483087, 0.4699761551869359, 0.4139059537618117, 0.39760995929467524, 0.3525207948091034, 0.37483175169872196, 0.38848647623264754, 0.39676639925756335, 0.3974408702346174, 0.3884840082893632, 0.3806754365076317, 0.3763281465971566, 0.3726187436137421, 0.3700304439118882, 0.3632838263037715, 0.3506105955183977, 0.34228904399074833, 0.3317155768831129, 0.32441761790433643, 0.32118699425838315, 0.3216402033083739, 0.3174296447953342, 0.3208048237740826, 0.32186808307360865])
curve3_y = np.array([0.0, 0.7066666666666667, 0.517645473461759, 0.5298221541969246, 0.5710374995096229, 0.6072219227142667, 0.5927479854561725, 0.5977791315364475, 0.6142891746574016, 0.6118095109530789, 0.6174851105641609, 0.6037096873366057, 0.6015543600362456, 0.5620148877772692, 0.5254222647652458, 0.49736751098598686, 0.4830372323886493, 0.4733959710567765, 0.47305315643154044, 0.46539741128651096, 0.46277971044852156, 0.44896393320280165, 0.4414150708523772, 0.44070353354681957, 0.43269636725194427, 0.436358916823449, 0.43691205782746295, 0.43307925408764686, 0.4229575901304314, 0.4147451502856579])

# 如果x轴有自定义值（例如时间、距离等），替换以下x值
x = np.arange(len(curve1_y))  # 默认x轴为等间距索引 [0, 1, 2, 3, 4]

# 计算每条曲线的AUC（使用梯形积分法）
def calculate_auc(x, y):
    return np.trapz(y, x)  # 梯形积分法计算曲线下面积

auc1 = calculate_auc(x, curve1_y)
auc2 = calculate_auc(x, curve2_y)
auc3 = calculate_auc(x, curve3_y)
plt.rcParams['font.sans-serif'] = ['SimHei']  # 例如使用黑体
plt.rcParams['axes.unicode_minus'] = False  # 解决负号显示问题
# 绘制对比图
plt.figure(figsize=(10, 6))

# 绘制三条曲线
plt.plot(x, curve1_y, color='blue', marker='o', linestyle='-', linewidth=2, label=f'对照组 (AUC = {auc1:.2f})')
plt.plot(x, curve2_y, color='green', marker='s', linestyle='--', linewidth=2, label=f'神经质为0 (AUC = {auc2:.2f})')
plt.plot(x, curve3_y, color='red', marker='^', linestyle=':', linewidth=2, label=f'神经质为1 (AUC = {auc3:.2f})')

# 设置坐标轴和样式
plt.xlabel('X Axis', fontsize=12)
plt.ylabel('Y Axis (Range 0-2)', fontsize=12)
plt.title('归一化聚类指数对比 with AUC', fontsize=14)
plt.ylim(0, 2.1)  # 根据数据范围调整y轴显示
plt.grid(True, linestyle='--', alpha=0.6)
plt.legend(loc='upper left', fontsize=10)
plt.tight_layout()
plt.show()